home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 2 / Atari Mega Archive CD - Volume 2.iso / minix / up1510b.tgz / up1510b / src / commands / sh / sh5.c.D < prev    next >
Text File  |  1990-07-25  |  9KB  |  435 lines

  1. *** /tmp/,RCSt1022169    Wed Jul 25 13:44:42 1990
  2. --- sh5.c    Thu Jul 12 01:03:31 1990
  3. ***************
  4. *** 1,5 ****
  5.   #define Extern extern
  6. ! #include "signal.h"
  7. ! #include "errno.h"
  8. ! #include "setjmp.h"
  9.   #include "sh.h"
  10. --- 1,6 ----
  11.   #define Extern extern
  12. ! #include <sys/types.h>
  13. ! #include <signal.h>
  14. ! #include <errno.h>
  15. ! #include <setjmp.h>
  16.   #include "sh.h"
  17. ***************
  18. *** 13,15 ****
  19. --- 14,21 ----
  20.   
  21. + static struct iobuf sharedbuf = {AFID_NOBUF};
  22. + static struct iobuf mainbuf = {AFID_NOBUF};
  23. + static unsigned bufid = AFID_ID;    /* buffer id counter */
  24.   
  25. + struct ioarg temparg = {0, 0, 0, AFID_NOBUF, 0};
  26.   int
  27. ***************
  28. *** 28,30 ****
  29.       c = readc();
  30. !     if (ec != '\'') {
  31.           if(c == '\\') {
  32. --- 34,36 ----
  33.       c = readc();
  34. !      if (ec != '\'' && ec != '`' && e.iop->task != XGRAVE) {
  35.           if(c == '\\') {
  36. ***************
  37. *** 47,48 ****
  38. --- 53,61 ----
  39.   int
  40. + eofc()
  41. + {
  42. +   return e.iop < e.iobase || (e.iop->peekc == 0 && e.iop->prev == 0);
  43. + }
  44. + int
  45.   readc()
  46. ***************
  47. *** 50,52 ****
  48.       register c;
  49. -     static int eofc;
  50.   
  51. --- 63,64 ----
  52. ***************
  53. *** 56,68 ****
  54.               return(c);
  55. -         } else if ((c = (*e.iop->iofn)(&e.iop->arg, e.iop)) != '\0') {
  56. -             if (c == -1) {
  57. -                 e.iop++;
  58. -                 continue;
  59. -             }
  60. -             if (e.iop == iostack)
  61. -                 ioecho(c);
  62. -             return(c);
  63.           }
  64. !     if (e.iop >= iostack ||
  65. !         multiline && eofc++ < 3)
  66.           return(0);
  67. --- 68,96 ----
  68.               return(c);
  69.           }
  70. !         else {
  71. !             if (e.iop->prev != 0) {
  72. !                 if ((c = (*e.iop->iofn)(e.iop->argp, e.iop)) != '\0') {
  73. !                     if (c == -1) {
  74. !                         e.iop++;
  75. !                         continue;
  76. !                     }
  77. !                     if (e.iop == iostack)
  78. !                         ioecho(c);
  79. !                     return(e.iop->prev = c);
  80. !                 }
  81. !                 else if (e.iop->task == XIO && e.iop->prev != '\n') {
  82. !                     e.iop->prev = 0;
  83. !                 if (e.iop == iostack)
  84. !                     ioecho('\n');
  85. !                     return '\n';
  86. !                 }
  87. !             }
  88. !             if (e.iop->task == XIO) {
  89. !             if (multiline)
  90. !                 return e.iop->prev = 0;
  91. !             if (talking && e.iop == iostack+1)
  92. !                 prs(prompt->value);
  93. !             }
  94. !         }
  95. !     if (e.iop >= iostack)
  96.           return(0);
  97. ***************
  98. *** 81,84 ****
  99.   void
  100. ! pushio(arg, fn)
  101. ! struct ioarg arg;
  102.   int (*fn)();
  103. --- 109,112 ----
  104.   void
  105. ! pushio(argp, fn)
  106. ! struct ioarg *argp;
  107.   int (*fn)();
  108. ***************
  109. *** 92,94 ****
  110.       e.iop->iofn = fn;
  111. !     e.iop->arg = arg;
  112.       e.iop->peekc = 0;
  113. --- 120,138 ----
  114.       e.iop->iofn = fn;
  115. !     if (argp->afid != AFID_NOBUF)
  116. !       e.iop->argp = argp;
  117. !     else {
  118. !       e.iop->argp  = ioargstack + (e.iop - iostack);
  119. !       *e.iop->argp = *argp;
  120. !       e.iop->argp->afbuf = e.iop == &iostack[0] ? &mainbuf : &sharedbuf;
  121. !       if (isatty(e.iop->argp->afile) == 0 &&
  122. !           (e.iop == &iostack[0] ||
  123. !            lseek(e.iop->argp->afile, 0L, 1) != -1)) {
  124. !         if (++bufid == AFID_NOBUF)
  125. !           bufid = AFID_ID;
  126. !         e.iop->argp->afid  = bufid;
  127. !       }
  128. !     }
  129. !     e.iop->prev  = ~'\n';
  130.       e.iop->peekc = 0;
  131. ***************
  132. *** 96,98 ****
  133.       e.iop->nlcount = 0;
  134. !     if (fn == filechar || fn == linechar || fn == nextchar)
  135.           e.iop->task = XIO;
  136. --- 140,142 ----
  137.       e.iop->nlcount = 0;
  138. !     if (fn == filechar || fn == linechar)
  139.           e.iop->task = XIO;
  140. ***************
  141. *** 164,166 ****
  142.    */
  143. ! static    int    xxchar(), qqchar();
  144.   
  145. --- 208,210 ----
  146.    */
  147. ! static    int    xxchar();
  148.   
  149. ***************
  150. *** 173,175 ****
  151.       if ((wp = *ap->awordlist++) != NULL) {
  152. !         PUSHIO(aword, wp, *ap->awordlist == NULL? qqchar: xxchar);
  153.           return(-1);
  154. --- 217,219 ----
  155.       if ((wp = *ap->awordlist++) != NULL) {
  156. !         PUSHIO(aword, wp, *ap->awordlist == NULL? strchar: xxchar);
  157.           return(-1);
  158. ***************
  159. *** 194,197 ****
  160.   
  161. ! static int
  162. ! qqchar(ap)
  163.   register struct ioarg *ap;
  164. --- 238,244 ----
  165.   
  166. ! /*
  167. !  * Produce the characters from a single word (string).
  168. !  */
  169. ! int
  170. ! strchar(ap)
  171.   register struct ioarg *ap;
  172. ***************
  173. *** 200,202 ****
  174.   
  175. !     if (ap->aword == NULL || (c = *ap->aword++) == '\0')
  176.           return(0);
  177. --- 247,249 ----
  178.   
  179. !     if (ap->aword == NULL || (c = *ap->aword++) == 0)
  180.           return(0);
  181. ***************
  182. *** 206,208 ****
  183.   /*
  184. !  * Produce the characters from a single word (string).
  185.    */
  186. --- 253,255 ----
  187.   /*
  188. !  * Produce quoted characters from a single word (string).
  189.    */
  190. ***************
  191. *** 209,211 ****
  192.   int
  193. ! strchar(ap)
  194.   register struct ioarg *ap;
  195. --- 256,258 ----
  196.   int
  197. ! qstrchar(ap)
  198.   register struct ioarg *ap;
  199. ***************
  200. *** 214,218 ****
  201.   
  202. !     if (ap->aword == 0 || (c = *ap->aword++) == 0)
  203.           return(0);
  204. !     return(c);
  205.   }
  206. --- 261,265 ----
  207.   
  208. !     if (ap->aword == NULL || (c = *ap->aword++) == 0)
  209.           return(0);
  210. !     return(c|QUOTE);
  211.   }
  212. ***************
  213. *** 228,229 ****
  214. --- 275,277 ----
  215.       char c;
  216. +     struct iobuf *bp = ap->afbuf;
  217.       extern int errno;
  218. ***************
  219. *** 230,231 ****
  220. --- 278,297 ----
  221.   
  222. +     if (ap->afid != AFID_NOBUF) {
  223. +       if ((i = ap->afid != bp->id) || bp->bufp == bp->ebufp) {
  224. +         if (i)
  225. +           lseek(ap->afile, ap->afpos, 0);
  226. +         do {
  227. +           i = read(ap->afile, bp->buf, sizeof(bp->buf));
  228. +         } while (i < 0 && errno == EINTR);
  229. +         if (i <= 0) {
  230. +           closef(ap->afile);
  231. +           return 0;
  232. +         }
  233. +         bp->id = ap->afid;
  234. +         bp->ebufp = (bp->bufp  = bp->buf) + i;
  235. +       }
  236. +       ap->afpos++;
  237. +       return *bp->bufp++ & 0177;
  238. +     }
  239.       do {
  240. ***************
  241. *** 315,333 ****
  242.   
  243. - /*
  244. -  * Return the next character from the command source,
  245. -  * prompting when required.
  246. -  */
  247. - int
  248. - nextchar(ap)
  249. - register struct ioarg *ap;
  250. - {
  251. -     register int c;
  252. -     if ((c = filechar(ap)) != 0)
  253. -         return(c);
  254. -     if (talking && e.iop <= iostack+1)
  255. -         prs(prompt->value);
  256. -     return(0);
  257. - }
  258.   void
  259. --- 381,382 ----
  260. ***************
  261. *** 435,440 ****
  262.   
  263. ! static    char *readhere();
  264.   
  265. - #define    NCPB    100    /* here text block allocation unit */
  266.   markhere(s, iop)
  267. --- 484,487 ----
  268.   
  269. ! static    void readhere();
  270.   
  271.   markhere(s, iop)
  272. ***************
  273. *** 452,453 ****
  274. --- 499,501 ----
  275.       h->h_iop = iop;
  276. +     iop->io_name = 0;
  277.       h->h_next = NULL;
  278. ***************
  279. *** 472,483 ****
  280.   {
  281. !     register struct here *h;
  282.   
  283. !     for (h = inhere; h != NULL; h = inhere) {
  284. !         h->h_iop->io_name = readhere(h->h_tag, h->h_dosub? 0: '\'');
  285. !         /* relink from inhere to acthere list */
  286. !         inhere = h->h_next;
  287. !         h->h_next = acthere;
  288. !         acthere = h;
  289.       }
  290. -     inhere = h;
  291.   }
  292. --- 520,533 ----
  293.   {
  294. !     register struct here *h, *hp;
  295.   
  296. !     /* Scan here files first leaving inhere list in place */
  297. !     for (hp = h = inhere; h != NULL; hp = h, h = h->h_next)
  298. !       readhere(&h->h_iop->io_name, h->h_tag, h->h_dosub? 0: '\'');
  299. !     /* Make inhere list active - keep list intact for scraphere */
  300. !     if (hp != NULL) {
  301. !       hp->h_next = acthere;
  302. !       acthere    = inhere;
  303. !       inhere     = NULL;
  304.       }
  305.   }
  306. ***************
  307. *** 484,487 ****
  308.   
  309. ! static char *
  310. ! readhere(s, ec)
  311.   register char *s;
  312. --- 534,538 ----
  313.   
  314. ! static void
  315. ! readhere(name, s, ec)
  316. ! char **name;
  317.   register char *s;
  318. ***************
  319. *** 496,497 ****
  320. --- 547,549 ----
  321.       tempname(tname);
  322. +     *name = strsave(tname, areanum);
  323.       tf = creat(tname, 0600);
  324. ***************
  325. *** 498,532 ****
  326.       if (tf < 0)
  327. !         return (0);
  328.       if (newenv(setjmp(errpt = ev)) != 0)
  329. !         return (0);
  330. !     if (e.iop == iostack && e.iop->iofn == filechar) {
  331. !         pushio(e.iop->arg, filechar);
  332.           e.iobase = e.iop;
  333. !     }
  334. !     for (;;) {
  335. !         if (talking && e.iop <= iostack)
  336. !             prs(cprompt->value);
  337. !         next = line;
  338. !         while ((c = getc(ec)) != '\n' && c) {
  339. !             if (ec == '\'')
  340. !                 c &= ~ QUOTE;
  341. !             if (next >= &line[LINELIM]) {
  342. !                 c = 0;
  343. !                 break;
  344.               }
  345. !             *next++ = c;
  346.           }
  347. !         *next = 0;
  348. !         if (strcmp(s, line) == 0 || c == 0)
  349. !             break;
  350. !         *next++ = '\n';
  351. !         write (tf, line, (int)(next-line));
  352.       }
  353. -     if (c == 0) {
  354. -         prs("here document `"); prs(s); err("' unclosed");
  355. -     }
  356.       close(tf);
  357. -     quitenv();
  358. -     /* correct area? */
  359. -     return (strsave(tname, areanum));
  360.   }
  361. --- 550,582 ----
  362.       if (tf < 0)
  363. !         return;
  364.       if (newenv(setjmp(errpt = ev)) != 0)
  365. !         unlink(tname);
  366. !     else {
  367. !         pushio(e.iop->argp, e.iop->iofn);
  368.           e.iobase = e.iop;
  369. !         for (;;) {
  370. !             if (talking && e.iop <= iostack)
  371. !                 prs(cprompt->value);
  372. !             next = line;
  373. !             while ((c = getc(ec)) != '\n' && c) {
  374. !                 if (ec == '\'')
  375. !                     c &= ~ QUOTE;
  376. !                 if (next >= &line[LINELIM]) {
  377. !